package web.Servlet;

import Service.TaobaoService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@WebServlet(name = "xzServlet",urlPatterns = "/xz")
public class xzServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        Date date=new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(date);
        Date parse =null;
        try {
             parse=simpleDateFormat.parse(format);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String names = req.getParameter("names");
        String mss = req.getParameter("mss");
        String price = req.getParameter("price");
                ArrayList arrayList = new ArrayList();
        arrayList.add(names);
        arrayList.add(mss);
        arrayList.add(parse);
        arrayList.add(price);
            TaobaoService taobaoService = new TaobaoService();
        try {
            taobaoService.xz(arrayList);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        resp.sendRedirect("/tb");
    }
}
